package ar.edu.unq.wannaplay.utils;

import org.apache.wicket.markup.html.link.Link;

import ar.edu.unq.wannaplay.pages.WPPage;
import ar.edu.unq.wannaplay.services.ServiceDeleteDTO;

public class DeleteLink<T> extends Link<Object> {

    private T object;

    private ServiceDeleteDTO<T> service;

    private Class<? extends WPPage> redirectTo;

    public DeleteLink(final String id, final T object, final ServiceDeleteDTO<T> service,
            final Class<? extends WPPage> redirect) {
        super(id);
        this.setObject(object);
        this.setService(service);
        redirectTo = redirect;

    }

    private static final long serialVersionUID = 1L;

    @Override
    public void onClick() {
        service.delete(object);
        this.setResponsePage(redirectTo);
    }

    public void setObject(final T object) {
        this.object = object;
    }

    public T getObject() {
        return object;
    }

    public void setService(final ServiceDeleteDTO<T> service) {
        this.service = service;
    }

    public ServiceDeleteDTO<T> getService() {
        return service;
    }

    public Class<? extends WPPage> getRedirectTo() {
        return redirectTo;
    }

    public void setRedirectTo(final Class<? extends WPPage> redirectTo) {
        this.redirectTo = redirectTo;
    }
}
